package com.zc58s.redpack.basic;

/**
 * @author : fujc-dev@qq.com
 */

public class Basic {

    public static String ip = "127.0.0.1";
    public static Integer port = 6379;
    public static String auth = "";

    public static int threadCount = 20;
    public static int hongBaoCount = 1000;

    /**
     * LIST类型，来模拟红包池
     */
    public static String hongbaoPoolKey = "hongbaoPoolKey";
    /**
     * LIST类型，记录所有用户抢红包的详情
     */
    public static String hongbaoDetailListKey = "hongbaoDetailListKey";
    /**
     * 记录已经抢过红包的用户ID，防止重复抢
     */
    public static String userIdRecordKey = "userIdRecordKey";


    /**
     *
     */
    public static String getHongBaoScript =
            "if redis.call('hexists',KEYS[3]，KEYS[4]) ~= 0 then\n" +
                    "\treturn nil\n" +
                    "else\n" +
                    "    local hongBao = redis.call('rpop',KEYS[1]); \n" +
                    "    if hongBao then\n" +
                    "\t\tlocal x =cjson.decode(hongBao);\n" +
                    "\t\tx['userId'] = KEYS[4];\n" +
                    "\t\tlocal re = cjson.encode(x); \n" +
                    "\t\tredis.call('hset', KEYS[3], KEYS[4],'1');\n" +
                    "\t\tredis.call('lpush', KEYS[2], re); \n" +
                    "\t\treturn re; \n" +
                    "    end\n" +
                    "end\n" +
                    "return nil";

}
